<template>
  <div>
    <van-field label="标的名称" v-model="name"/>
    <van-field label="标的金额" v-model="money"/>
    <van-field label="利率" v-model="interest_rate"/>
    &nbsp;&nbsp;&nbsp;选择使用时间 <select name="" id="" v-model="time1">
    <option :value="i" v-for="i in time" :key="i">{{ i }}月</option>
  </select>
    <van-field label="借款用途" v-model="use"/>
    <van-button @click="send">提交标地</van-button>

    <van-popup v-model:show="show_hours" closeable close-icon="close" :style="{ height: '40%' ,width: '30%' }">
      <center><h1>您借款的金额为{{money}}</h1>
        <h3>还款金额为{{Number(price)+Number(money)}}</h3></center>
      <van-field v-model="password" type="password" label="密码" />
      <van-button @click="queren">确认</van-button>
    </van-popup>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      time: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
      name: '',
      time1: '',
      money: '',
      use: '',
      uid: localStorage.getItem('usrid'),
      interest_rate: '',
      show_hours:false,
      price:'',
      password:''
    }

  },
  methods: {
    queren(){

      this.myaxios('http://localhost:5000/get_user', 'get', {
        'uid': localStorage.getItem('usrid'),
        'code': this.password,
      })
          .then(res => {
            console.log(res)
            if (res.code=='200'){
              axios.post('http://localhost:5000/addmark', {
                'name': this.name,
                'interest_rate': this.interest_rate,
                'money': this.money, 'time': this.time1, 'use1': this.use, 'userid': this.uid
              }).then(res => {
                console.log(res.data);
                this.show_hours=false
              })
            }else {
              alert(res.msg)
            }
          })
    },
    send() {
      this.price=((this.money*this.interest_rate)/12)*this.time1
      this.show_hours=true
      // axios.post('http://localhost:5000/addmark', {
      //   'name': this.name,
      //   'interest_rate': this.interest_rate,
      //   'money': this.money, 'time': this.time1, 'use1': this.use, 'userid': this.uid
      // }).then(res => {
      //   console.log(res.data);
      // })
    }
  }
}
</script>

<style>

</style>
